package com.chukun.disruptor;

import com.chukun.disruptor.netty.common.CommonConstants;
import com.chukun.disruptor.netty.disruptor.consumer.MessageConsumer;
import com.chukun.disruptor.netty.disruptor.factory.RingBufferWorkerPoolFactory;
import com.chukun.disruptor.netty.server.NettyServer;
import com.chukun.disruptor.netty.server.NettyServerConsumer;
import com.lmax.disruptor.BlockingWaitStrategy;
import com.lmax.disruptor.dsl.ProducerType;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author chukun
 * disruptor 服务启动端
 */
@SpringBootApplication
public class JavaDisruptorApplicationServer {

    public static void main(String[] args) {
        SpringApplication.run(JavaDisruptorApplicationServer.class, args);

        //创建服务端消费者实例
        MessageConsumer[] serverConsumers = new NettyServerConsumer[5];

        for(int i=0;i<serverConsumers.length;i++){
            MessageConsumer  serverConsumer = new NettyServerConsumer("code:serverID: "+i);
            serverConsumers[i]=serverConsumer;
        }

        //启动服务端的disruptor
        RingBufferWorkerPoolFactory.getInstance().initAndStart(ProducerType.MULTI, CommonConstants.BUFFER_SIZE,new BlockingWaitStrategy(),serverConsumers);


        new NettyServer();
//        new NettyClient();
    }
}
